//模型加载类
/*var loader;
var loaderType = {
    BabylonLoader:0,
    GLTFLoader:1,
    MMDLoader:2,
    MTLLoader:3,
    OBJLoader:4,
    OBJLoader2:5,
    PCDLoader:6,
    PDBLoader:7,
    SVGLoader:8,
    TGALoader:9,
    PRWMLoader:10
};

class LoaderFactory{
    getLoader(type){
        switch(type){
            case loaderType.BabylonLoader || 0:
                loader = new THREE.BabylonLoader();
                break;
            case loaderType.GLTFLoader || 1:
                loader = new THREE.GLTFLoader();
                break;
            case loaderType.MMDLoader || 2:
                loader = new THREE.MMDLoader();
                break;
            case loaderType.MTLLoader || 3:
                loader = new THREE.MTLLoader();
                break;
            case loaderType.OBJLoader || 4:
                loader = new THREE.OBJLoader();
                break;
            case loaderType.OBJLoader2 || 5:
                loader = new THREE.OBJLoader2();
                break;
            case loaderType.PCDLoader || 6:
                loader = new THREE.PCDLoader();
                break;
            case loaderType.PDBLoader|| 7:
                loader = new THREE.PDBLoader();
                break;
            case loaderType.SVGLoader || 8:
                loader = new THREE.SVGLoader();
                break;
            case loaderType.TGALoader || 9:
                loader = new THREE.TGALoader();
                break;
            case loaderType.PRWMLoader || 10:
                loader = new THREE.PRWMLoader();
                break;
            default:
                console.log("please choose the loader...")
        }
    }
}*/

class ModelLoader{
    load(path,modelName){}
//加载进度函数
    static onProgress(xhr){
            let percentComplete = xhr.loaded / xhr.total * 100;
            console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
    };
//加载出错回调函数
    static onError(error){
        console.log("An error happened!"+error)
    };
//加载 mtl资源
//MTLLoader的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createMTLLoader(path,modelName){
            return new Promise((resolve,reject)=>{
                let mtlLoader = new THREE.MTLLoader();
                mtlLoader.setPath(path);
                mtlLoader.load(modelName, (object) => {
                    object.preload();
                    resolve(object);
                }, null, (error) => {
                    reject(error);
                })
            })
    }
//加载 .obj资源
//ObjectLoader的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createOBJLoader(path,modelName,material){
        return new Promise((resolve,reject)=>{
            let objLoader = new THREE.OBJLoader();
            objLoader.setPath(path);
            objLoader.setMaterials(material);
            objLoader.load(modelName, (object) => {
                resolve(object);
            }, null, (error) => {
                reject(error);
            })
        })
    }
//加载 .babylonLoader资源
//BabylonLoader 的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createBabylonLoader(path,modelName){
        return new Promise((resolve,reject)=>{
            let babylonLoader = new BabylonLoader();
            babylonLoader.setPath(path);
            babylonLoader.load(modelName, (object) => {
                resolve(object);
            }, null, (error) => {
                reject(error);
            })
        })
    }
//加载 .gltf资源
//GLTFLoader 的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createGLTFLoader(path,modelName){
        return new Promise((resolve,reject)=>{
            let gltfLoader = new GLTFLoader();
            gltfLoader.setPath(path);
            gltfLoader.load(modelName, (object) => {
                resolve(object);
            }, null, (error) => {
                reject(error);
            })
        })
    }
//加载 .pmd、.pmx、.vmd、.vpd资源
//MMDLoader 的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createMMDLoader(path,modelName){
        return new Promise((resolve,reject)=>{
        let mmdLoader = new MMDLoader();
        mmdLoader.setPath(path);
        mmdLoader.load(modelName, (object) => {
            resolve(object);
        }, null, (error) => {
            reject(error);
        })
    })}
//加载 .pcd资源
//PCDLoader 的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createPCDLoader(path,modelName){
        return new Promise((resolve,reject)=>{
            let pcdLoader = new PCDLoader();
            pcdLoader.setPath(path);
            pcdLoader.load(modelName, (object) => {
                resolve(object);
            }, null, (error) => {
                reject(error);
            })
        })
    }
//加载 .pdb资源
//PCDLoader 的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createPDBLoader(path,modelName){
        return new Promise((resolve,reject)=>{
            let pdbLoader = new PDBLoader();
            pdbLoader.setPath(path);
            pdbLoader.load(modelName, (object) => {
                resolve(object);
            }, null, (error) => {
                reject(error);
            })
        })
    }
//加载 .svg资源
//SVGLoader 的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createSVGLoader(path,modelName){
        return new Promise((resolve,reject)=>{
            let svgLoader = new THREE.SVGLoader();
            svgLoader.setPath(path);
            svgLoader.load(modelName, (object) => {
                resolve(object);
            }, null, (error) => {
                reject(error);
            })
        })
    }

//加载 .tga资源
//TGALoader 的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createTGALoader(path,modelName){
        return new Promise((resolve,reject)=>{
            let tgaLoader = new THREE.TGALoader();
            tgaLoader.setPath(path);
            tgaLoader.load(modelName, (object) => {
                resolve(object);
            }, null, (error) => {
                reject(error);
            })
        })
    }
//加载 .prwm资源
//PRWMLoader 的load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : null
    static createPRWMLoader(path,modelName){
        return new Promise((resolve,reject)=>{
            let prwmLoader = new THREE.PRWMLoader();
            prwmLoader.setPath(path);
            prwmLoader.load(modelName, (object) => {
                resolve(object);
            }, null, (error) => {
                reject(error);
            })
        })
    }
}

export {ModelLoader}